package com.tul.vapp.servicecenter.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tul.cusa.common.exception.SysException;
import com.tul.vapp.servicecenter.common.ErrorCodeConstant;
import com.tul.vapp.servicecenter.dao.IUserDao;
import com.tul.vapp.servicecenter.entity.User;
import com.tul.vapp.servicecenter.service.IUserService;

/**
 * base service
 *
 * @author wujunlei
 * @version 1.0
 * @since 2018/1/2
 */
@Service
public class UserService implements IUserService {

	/**
	 * log
	 */
	private static final Logger TRACER = LoggerFactory.getLogger(UserService.class);

	/**
	 * user dao
	 */
	@Autowired
	private IUserDao userDao;

	/**
	 * query
	 *
	 * @param user user
	 * @return str
	 */
	@Override
	public User findByUser(User user) {
		User userInfo = null;
		try {
			userInfo = userDao.findByUser(user);
		} catch (Exception e) {
			TRACER.error("data access error", e);
			throw new SysException(ErrorCodeConstant.SYS_DB_ACCESS_ERROR);
		}
		return userInfo;
	}

	/**
	 * update
	 *
	 * @param user user
	 * @return str
	 */
	@Override
	public Boolean updateUser(User user) {
		Integer result = null;
		try {
			result = userDao.update(user);
		} catch (Exception e) {
			TRACER.error("data access error", e);
			throw new SysException(ErrorCodeConstant.SYS_DB_ACCESS_ERROR);
		}
		if (result > 0) {
			return true;
		}
		return false;
	}
}
